package maps;

import java.sql.Timestamp;
import java.util.HashMap;

/**
 * Maps are magic!
 * @author Lucas
 *
 */
public class HashMapExercise {

	/**
	 * Tries to demonstrate hash tables run in O(1) time. Which is pretty speedy./understatement
	 * @param numIterations
	 */
	public void run(int numIterations){
		HashMap<String, Integer> hash = new HashMap<String, Integer>(); //Made me parameterize the HashMap with <String, Integer> for safety.		
		long timeBefore = System.currentTimeMillis();
		System.out.println(timeBefore + " milliseconds");
		for(int i = 0; i < numIterations; i++){
			hash.put("Key for " + i, i);
		}
		for(int i = 0; i < numIterations; i++){
			hash.get("Key for " +i);
			//System.out.println("Value for key:\tKey for " + i + " = " + hash.get("Key for " +i));
		}
		long timeAfter = System.currentTimeMillis();
		System.out.println(timeAfter + " milliseconds");
		long timeTaken = (long)(timeAfter - timeBefore);
		System.out.println("Time taken for " + numIterations + " iterations: " + (double)timeTaken/1000 + " seconds");
	}
	
	/**
	 * Shows you can make HashMaps equal but simply putting an = sign.
	 * That's fucking amazing. No homo.
	 * @param numIterations
	 */
	public void canYouMakeThemEqual(int numIterations){
		HashMap<String, Integer> hash = new HashMap<String, Integer>(); //Made me parameterize the HashMap with <String, Integer> for safety.
		for(int i = 0; i < numIterations; i++){
			hash.put("Key" + i, i);
		}
		HashMap<String, Integer> compareMap = new HashMap<String, Integer>();
		compareMap = hash;
		for(int i = 0; i < numIterations; i++){
			//compareMap.get("Key for " +i);
			System.out.println("compareMap\tValue for key:\tKey" + i + " = " + compareMap.get("Key" +i));
		}
	}
	
	public static void main(String[] args) {
		HashMapExercise hme = new HashMapExercise();
		hme.run(16);
		hme.canYouMakeThemEqual(16);
		//hme.run(2000);
	}

}
